PyIgnition

https://github.com/animatinator/PyIgnition update for Python 3
Clone: git clone https://git.frombelow.net/PyIgnition.git
Log | Files | Refs | README

keyframes test.py (1517B)


      1 ## Keyframing test
      2 
      3 import keyframes, interpolate, pygame, sys
      4 
      5 
      6 screen = pygame.display.set_mode((800, 600))
      7 clock = pygame.time.Clock()
      8 
      9 
     10 class Circle:
     11 	def __init__(self, pos, colour, radius, screen):
     12 		self.x = pos[0]
     13 		self.y = pos[1]
     14 		self.r = colour[0]
     15 		self.g = colour[1]
     16 		self.b = colour[2]
     17 		self.rad = radius
     18 		self.screen = screen
     19 		self.variables = {"x":self.x, "y":self.y, "r":self.r, "g":self.g, "b":self.b, "rad":self.rad}
     20 		self.keyframes = []
     21 		self.keyframes.append(keyframes.Keyframe(1, self.variables))
     22 		self.keyframes.append(keyframes.Keyframe(200, {"x":800, "y":600}))
     23 		self.keyframes.append(keyframes.Keyframe(300, {"r":255, "g":0, "b":100}))
     24 		self.keyframes.append(keyframes.Keyframe(350, {"r":0, "y":0}))
     25 		self.keyframes.append(keyframes.Keyframe(400, {"x":400, "y":300, "rad":500}))
     26 		self.curframe = 1
     27 	
     28 	def Update(self):
     29 		self.variables = interpolate.InterpolateKeyframes(self.curframe, self.variables, self.keyframes)
     30 		self.curframe = self.curframe + 1
     31 	
     32 	def Draw(self):
     33 		pygame.draw.circle(self.screen,
     34 				   (int(self.variables["r"]), int(self.variables["g"]), int(self.variables["b"])),
     35 				   (int(self.variables["x"]), int(self.variables["y"])), int(self.variables["rad"]))
     36 
     37 
     38 circle = Circle((0, 0), (0, 255, 0), 10, screen)
     39 
     40 while True:
     41 	for event in pygame.event.get():
     42 		if event.type == pygame.QUIT:
     43 			sys.exit()
     44 	
     45 	screen.fill((0, 0, 0))
     46 	circle.Update()
     47 	circle.Draw()
     48 	
     49 	pygame.display.update()
     50 	clock.tick(30)